package com.example.xianji.activity;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.bean.YiJi_Class;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;
import com.example.xianji.widgets.CustomProgressDialog;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.BitmapDrawable;
import android.text.ClipboardManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Main_Send_XuQiuActivity extends Activity implements OnClickListener {
    /*************************发布需求页面****************************/
    private RelativeLayout send_xuqiu_back;
    private ClipboardManager clipboard;
    private InputMethodManager manager;
    private Button button_yiji_xuqiu, button_erji_fenlei, button_xuqiu_send;
    //    private SharedPreferences sp;
//    private Editor ed;
    private LinearLayout layout, linear_layout_send_xuqiu;
    private ListView show_listview;
    private PopupWindow show_popupWindow;
    private ArrayList<YiJi_Class> list = new ArrayList<YiJi_Class>();
    private EditText edittext_title, edittext_details, edittext_yusuan;
    private boolean yiji_flag = false, erji_flag = false, province_flag = false, city_flag = false, distrct_flag = false;
    private int yiji_indext = 1, province_indext = 1, city_indext = 1;
    private int cid, erji_id, province_id, city_id, distrct_id;
    private Button xuqiu_province_button, xuqiu_city_button, xuqiu_distrct_button;
    private CustomProgressDialog mCustomProgressDialog;

    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                show_listview.setAdapter(new MyAdapter());
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
            }
            if (msg.what == 2) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_main__send__xu_qiu);
        //XJApplication.getInstance().addActivity(this);
        send_xuqiu_back = (RelativeLayout) findViewById(R.id.relative_layout_send_xuqiu_back);
        clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        hideKeyboard();

//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();
        button_yiji_xuqiu = (Button) findViewById(R.id.button_yiji_xuqiu);
        button_erji_fenlei = (Button) findViewById(R.id.button_erji_fenlei);
        edittext_title = (EditText) findViewById(R.id.edittext_title);
        edittext_details = (EditText) findViewById(R.id.edittext_details);
        edittext_yusuan = (EditText) findViewById(R.id.edittext_yusuan);
        xuqiu_province_button = (Button) findViewById(R.id.xuqiu_province_button);
        xuqiu_city_button = (Button) findViewById(R.id.xuqiu_city_button);
        xuqiu_distrct_button = (Button) findViewById(R.id.xuqiu_distrct_button);
        button_xuqiu_send = (Button) findViewById(R.id.button_xuqiu_send);
        linear_layout_send_xuqiu = (LinearLayout) findViewById(R.id.linear_layout_send_xuqiu);
        send_xuqiu_back.setOnClickListener(this);
        button_yiji_xuqiu.setOnClickListener(this);
        button_erji_fenlei.setOnClickListener(this);
        xuqiu_province_button.setOnClickListener(this);
        xuqiu_city_button.setOnClickListener(this);
        xuqiu_distrct_button.setOnClickListener(this);
        button_xuqiu_send.setOnClickListener(this);
        linear_layout_send_xuqiu.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.relative_layout_send_xuqiu_back) {
            Main_Send_XuQiuActivity.this.finish();
        } else if (v.getId() == R.id.button_yiji_xuqiu) {
            Photo_show();
            show_popupWindow.showAtLocation(findViewById(R.id.send_fuwu), Gravity.BOTTOM, 0, 0);
            mCustomProgressDialog = CustomProgressDialog.createDialog(this);
            mCustomProgressDialog.setCanceledOnTouchOutside(false);
            mCustomProgressDialog.show();
            XJApplication.cachThreadPool.execute(new Runnable() {

                @Override
                public void run() {
                    yiji_fenlei();
                }
            });


            show_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    button_yiji_xuqiu.setText(list.get(arg2).getName());
                    button_yiji_xuqiu.setTextColor(getResources().getColor(R.color.black3F));
                    cid = list.get(arg2).getId();
                    yiji_indext++;
                    if (yiji_indext > 2) {
                        button_erji_fenlei.setText("请选择二级分类");
                        button_erji_fenlei.setTextColor(getResources().getColor(R.color.gray98));
                        erji_flag = false;
                    }
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                    yiji_flag = true;
                }
            });

        } else if (v.getId() == R.id.button_erji_fenlei) {
            if (yiji_flag) {
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.send_fuwu), Gravity.BOTTOM, 0, 0);
                mCustomProgressDialog = CustomProgressDialog.createDialog(this);
                mCustomProgressDialog.setCanceledOnTouchOutside(false);
                mCustomProgressDialog.show();
                XJApplication.cachThreadPool.execute(new Runnable() {

                    @Override
                    public void run() {
                        erji_fenlei();
                    }
                });

                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                                            int arg2, long arg3) {
                        button_erji_fenlei.setText(list.get(arg2).getName());
                        button_erji_fenlei.setTextColor(getResources().getColor(R.color.black3F));
                        erji_id = list.get(arg2).getId();
                        erji_flag = true;
                        show_popupWindow.dismiss();
                        show_popupWindow = null;
                    }
                });
            } else {

                Toast.makeText(Main_Send_XuQiuActivity.this, "请先选择一级分类", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.xuqiu_province_button) {
            Photo_show();
            show_popupWindow.showAtLocation(findViewById(R.id.send_fuwu), Gravity.BOTTOM, 0, 0);
            mCustomProgressDialog = CustomProgressDialog.createDialog(this);
            mCustomProgressDialog.setCanceledOnTouchOutside(false);
            mCustomProgressDialog.show();
            XJApplication.cachThreadPool.execute(new Runnable() {
                public void run() {
                    get_province();
                }
            });
            show_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    xuqiu_province_button.setText(list.get(arg2).getName());
                    xuqiu_province_button.setTextColor(getResources().getColor(R.color.black3F));
                    province_flag = true;
                    province_id = list.get(arg2).getId();
                    province_indext++;
                    if (province_indext > 2) {
                        xuqiu_city_button.setText("请选择城市");
                        xuqiu_city_button.setTextColor(getResources().getColor(R.color.gray98));
                        xuqiu_distrct_button.setText("请选择区");
                        city_flag = false;
                        distrct_flag = false;
                        xuqiu_distrct_button.setTextColor(getResources().getColor(R.color.gray98));
                    }
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                    yiji_flag = true;
                }
            });

        } else if (v.getId() == R.id.xuqiu_city_button) {
            if (province_flag) {
                mCustomProgressDialog = CustomProgressDialog.createDialog(this);
                mCustomProgressDialog.setCanceledOnTouchOutside(false);
                mCustomProgressDialog.show();
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.send_fuwu), Gravity.BOTTOM, 0, 0);
                if (xuqiu_province_button.getText().toString().equals("北京") || xuqiu_province_button.getText().toString().equals("上海") || xuqiu_province_button.getText().toString().equals("天津") ||
                        xuqiu_province_button.getText().toString().equals("香港") || xuqiu_province_button.getText().toString().equals("台湾")
                        ) {
                    get_teshu_province();
                } else {
                    XJApplication.cachThreadPool.execute(new Runnable() {

                        @Override
                        public void run() {
                            get_city();
                        }
                    });
                }
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                                            int position, long id) {
                        xuqiu_city_button.setText(list.get(position).getName());
                        xuqiu_city_button.setTextColor(getResources().getColor(R.color.black3F));
                        city_flag = true;
                        city_id = list.get(position).getId();
                        city_indext++;
                        if (city_indext > 2) {
                            xuqiu_distrct_button.setText("请选择区域");
                            xuqiu_distrct_button.setTextColor(getResources().getColor(R.color.gray98));
                            distrct_flag = false;
                        }
                        show_popupWindow.dismiss();
                        show_popupWindow = null;

                    }
                });

            } else {
                Toast.makeText(Main_Send_XuQiuActivity.this, "请先选择省份", Toast.LENGTH_SHORT).show();

            }

        } else if (v.getId() == R.id.xuqiu_distrct_button) {
            if (city_flag) {
                Photo_show();
                show_popupWindow.showAtLocation(findViewById(R.id.send_fuwu), Gravity.BOTTOM, 0, 0);
                mCustomProgressDialog = CustomProgressDialog.createDialog(this);
                mCustomProgressDialog.setCanceledOnTouchOutside(false);
                mCustomProgressDialog.show();
                XJApplication.cachThreadPool.execute(new Runnable() {

                    @Override
                    public void run() {
                        get_distrct();
                    }
                });

                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                                            int arg2, long arg3) {
                        xuqiu_distrct_button.setText(list.get(arg2).getName());
                        xuqiu_distrct_button.setTextColor(getResources().getColor(R.color.black3F));
                        distrct_flag = true;
                        distrct_id = list.get(arg2).getId();
                        show_popupWindow.dismiss();
                        show_popupWindow = null;
                    }
                });

            } else {
                Toast.makeText(Main_Send_XuQiuActivity.this, "请先选择城市", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.button_xuqiu_send) {
            if (yiji_flag) {
                if (erji_flag) {
                    if (edittext_title.getText().toString().length() > 0) {
                        if (edittext_details.getText().toString().length() > 0) {
                            if (province_flag) {
                                if (city_flag) {
                                    if (distrct_flag) {
                                        mCustomProgressDialog = CustomProgressDialog.createDialog(this);
                                        mCustomProgressDialog.setCanceledOnTouchOutside(false);
                                        mCustomProgressDialog.show();
                                        XJApplication.cachThreadPool.execute(new Runnable() {

                                            @Override
                                            public void run() {
                                                get_xuqiu_tijiao();
                                            }
                                        });
                                    } else {
                                        Toast.makeText(Main_Send_XuQiuActivity.this, "请选择地区", Toast.LENGTH_SHORT).show();
                                    }
                                } else {
                                    Toast.makeText(Main_Send_XuQiuActivity.this, "请选择城市", Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                Toast.makeText(Main_Send_XuQiuActivity.this, "请选择省份", Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(Main_Send_XuQiuActivity.this, "请填写需求内容", Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(Main_Send_XuQiuActivity.this, "请填写需求标题", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(Main_Send_XuQiuActivity.this, "请选择二级分类", Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(Main_Send_XuQiuActivity.this, "请选择一级分类", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.linear_layout_send_xuqiu) {
            if (show_popupWindow != null) {
                show_popupWindow.dismiss();
                show_popupWindow = null;
            }
        }
    }

    /**
     * 隐藏软键盘
     */
    private void hideKeyboard() {
        if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (getCurrentFocus() != null)
                manager.hideSoftInputFromWindow(getCurrentFocus()
                        .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }

    /**
     * 省份请求
     */
    public void get_province() {
        HashMap<String, Object> map = new HashMap<String, Object>();


        map.put("pid", 0);
        Log.i("进入进入进入", "进入进入进入");

        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));

                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_Send_XuQiuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();

                        if (mCustomProgressDialog != null) {
                            mCustomProgressDialog.dismiss();

                            mCustomProgressDialog = null;
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
                Toast.makeText(Main_Send_XuQiuActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 特殊省份请求
     */
    public void get_teshu_province() {
        list.clear();
        YiJi_Class mYiJi_Class = new YiJi_Class();
        mYiJi_Class.setId(province_id);
        mYiJi_Class.setName(xuqiu_province_button.getText().toString());
        list.add(mYiJi_Class);
        handler.sendEmptyMessage(1);
    }

    /**
     * 地区请求
     */
    public void get_city() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", province_id);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_Send_XuQiuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                        if (mCustomProgressDialog != null) {
                            mCustomProgressDialog.dismiss();
                            mCustomProgressDialog = null;
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
                Toast.makeText(Main_Send_XuQiuActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 地区请求
     */
    public void get_distrct() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("pid", city_id);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.place,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_Send_XuQiuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                    if (mCustomProgressDialog != null) {
                        mCustomProgressDialog.dismiss();
                        mCustomProgressDialog = null;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
                Toast.makeText(Main_Send_XuQiuActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void yiji_fenlei() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.yiji_fenlei,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        JSONArray array1 = array.getJSONArray(0);
                        for (int i = 0; i < array1.length(); i++) {
                            JSONObject object = array1.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(object.getInt("id"));
                            mYiJi_Class.setName(object.getString("name"));
                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_Send_XuQiuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                        if (mCustomProgressDialog != null) {
                            mCustomProgressDialog.dismiss();
                            mCustomProgressDialog = null;
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
                Toast.makeText(Main_Send_XuQiuActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }


    public void erji_fenlei() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("cid", cid);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.erji_fenlei,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        JSONArray array1 = array.getJSONArray(0);
                        for (int i = 0; i < array1.length(); i++) {
                            JSONObject object = array1.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(object.getInt("id"));
                            mYiJi_Class.setName(object.getString("name"));
                            list.add(mYiJi_Class);
                        }
                        handler.sendEmptyMessage(1);
                    } else {
                        Toast.makeText(Main_Send_XuQiuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                        if (mCustomProgressDialog != null) {
                            mCustomProgressDialog.dismiss();
                            mCustomProgressDialog = null;
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
                Toast.makeText(Main_Send_XuQiuActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    public void get_xuqiu_tijiao() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("parent", cid);
        map.put("category", erji_id);
        map.put("title", edittext_title.getText().toString());
        map.put("details", edittext_details.getText().toString());
        if (edittext_yusuan.getText().toString().length() == 0) {
            map.put("budget", "面议");
        } else {
            map.put("budget", edittext_yusuan.getText().toString());
        }
        map.put("province", province_id);
        map.put("city", city_id);
        map.put("district", distrct_id);
        JSONObject params = new JSONObject(map);
        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.tijiao_xuqiu,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    Toast.makeText(Main_Send_XuQiuActivity.this, response.getString("msg"), Toast.LENGTH_SHORT).show();
                    if (response.getInt("status") == 1) {
                        Main_Send_XuQiuActivity.this.finish();
                    }
                    handler.sendEmptyMessage(2);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (mCustomProgressDialog != null) {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
                Toast.makeText(Main_Send_XuQiuActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(30 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }


    private void Photo_show() {
        layout = (LinearLayout) LayoutInflater.from(
                Main_Send_XuQiuActivity.this).inflate(
                R.layout.information_shoow_photo, null);
        show_listview = (ListView) layout.findViewById(R.id.information_photo_listview);

        show_listview.setCacheColorHint(0);
        show_popupWindow = new PopupWindow(layout, WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT);
        show_popupWindow.setBackgroundDrawable(new BitmapDrawable());


        show_popupWindow.setHeight(700);
        show_popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
        show_popupWindow.update();
        show_popupWindow.setOutsideTouchable(true);
        show_popupWindow.setFocusable(true);
        show_popupWindow.setContentView(layout);
    }

    class MyAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int arg0) {
            return arg0;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder mHolder;
            if (convertView == null) {
                mHolder = new Holder();
                convertView = View.inflate(Main_Send_XuQiuActivity.this, R.layout.listview_item_layout, null);
                mHolder.place_text = (TextView) convertView.findViewById(R.id.place_text);
                convertView.setTag(mHolder);
            }
            mHolder = (Holder) convertView.getTag();
            mHolder.place_text.setText(list.get(position).getName());
            return convertView;
        }
    }

    class Holder {
        TextView place_text;
    }
}

